package com.ruoyi.web.controller.meterread;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.WaterMonthlyUsage;
import com.ruoyi.system.domain.vo.WaterUserMeterVO;
import com.ruoyi.system.service.IWaterMonthlyUsageService;
import com.ruoyi.system.service.IWaterUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 月用水量汇总Controller
 *
 * @author ruoyi
 * @date 2025-09-20
 */
@RestController
@RequestMapping("/meterread/monthusage")
public class WaterMonthlyUsageController extends BaseController
{
    @Autowired
    private IWaterUserService waterUserService;
    @Autowired
    private IWaterMonthlyUsageService waterMonthlyUsageService;

    /**
     * 查询远传表档案列表
     */
    @PreAuthorize("@ss.hasPermi('meterread:monthusage:list')")
    @GetMapping("/list")
    public TableDataInfo list(WaterUserMeterVO userMeterVO)
    {
        startPage();
        List<WaterUserMeterVO> list = waterUserService.selectWaterUserMeterList(userMeterVO);
        return getDataTable(list);
    }

    /**
     * 查询月用水量汇总列表
     */
    @PreAuthorize("@ss.hasPermi('meterread:monthusage:hisList')")
    @GetMapping("/hisList")
    public TableDataInfo list(WaterMonthlyUsage waterMonthlyUsage)
    {
        startPage();
        List<WaterMonthlyUsage> list = waterMonthlyUsageService.selectWaterMonthlyUsageList(waterMonthlyUsage);
        return getDataTable(list);
    }

    /**
     * 导出月用水量汇总列表
     */
    @PreAuthorize("@ss.hasPermi('meterread:monthusage:export')")
    @Log(title = "月用水量汇总", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void eport(HttpServletResponse response, WaterMonthlyUsage waterMonthlyUsage)
    {
        List<WaterMonthlyUsage> list = waterMonthlyUsageService.selectWaterMonthlyUsageList(waterMonthlyUsage);
        ExcelUtil<WaterMonthlyUsage> util = new ExcelUtil<WaterMonthlyUsage>(WaterMonthlyUsage.class);
        util.exportExcel(response, list, "月用水量汇总数据");
    }

    /**
     * 获取月用水量汇总详细信息
     */
    @PreAuthorize("@ss.hasPermi('meterread:monthusage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(waterMonthlyUsageService.selectWaterMonthlyUsageById(id));
    }

    /**
     * 新增月用水量汇总
     */
    @PreAuthorize("@ss.hasPermi('meterread:monthusage:add')")
    @Log(title = "月用水量汇总", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WaterMonthlyUsage waterMonthlyUsage)
    {
        return toAjax(waterMonthlyUsageService.insertWaterMonthlyUsage(waterMonthlyUsage));
    }

    /**
     * 修改月用水量汇总
     */
    @PreAuthorize("@ss.hasPermi('meterread:monthusage:edit')")
    @Log(title = "月用水量汇总", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WaterMonthlyUsage waterMonthlyUsage)
    {
        return toAjax(waterMonthlyUsageService.updateWaterMonthlyUsage(waterMonthlyUsage));
    }

    /**
     * 删除月用水量汇总
     */
    @PreAuthorize("@ss.hasPermi('meterread:monthusage:remove')")
    @Log(title = "月用水量汇总", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(waterMonthlyUsageService.deleteWaterMonthlyUsageByIds(ids));
    }
}
